package com.wingsfrog.ZcVideo;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

//import com.HkstreamNatNew.utils.ApplicationUtils;
//import com.HkstreamNatNew.utils.CancelAlarmPushThread;
//import com.HkstreamNatNew.utils.SetAlarmPushThread;
//import com.HkstreamNatNew.utils.Utils;
import com.wingsfrog.ZcVideo.PlayNode;
import com.wingsfrog.genius_rc.R;
import com.Player.Core.PlayerClient;
import com.Player.Source.SDKError;

@SuppressLint("HandlerLeak")
public class PlayLayout extends RelativeLayout implements Runnable {
	public static final int ROW_TOTAL_1 = 1;
	public static final int ROW_TOTAL_4 = 4;
	public static final int ROW_TOTAL_8 = 8;
	public static final int ROW_TOTAL_9 = 9;
	public static final int ROW_TOTAL_12 = 12;
	public static final int ROW_TOTAL_16 = 16;
	public static final int ROW_TOTAL_25 = 25;

	public static final int STATE = 0;
	public static final byte READY = 0; // 准备就绪
	public static final byte CONNECTTING = 1;// 连接中
	public static final byte PLAYING = 2;// 播放中
	public static final byte STOP = 4;// 停止
	public static final byte CONNECTTING_FAIL = 3;// 连接失败

	private static final int NPC_D_MPI_MON_ERROR_USERID_ERROR = -101; // 用户ID或用户名错误
	private static final int NPC_D_MPI_MON_ERROR_USERPWD_ERROR = -102; // 用户密码错误
	private static final int NPC_D_MPI_MON_ERROR_REJECT_ACCESS = -111; // 权限不够
	public final int PlayNumber = 16;
	public VideoCanvas canvas[] = new VideoCanvas[PlayNumber];
	private CanvasInfo[] ci = new CanvasInfo[PlayNumber];
	private Context con;
	private boolean isRun = false;
	public int index = 0;
	private int count = 0;
	private long fTime = 0;
	float cx = 0;
	float cy = 0;
	boolean isMoved = false;
	private boolean isSinglePlayView = false;
	public boolean isLand = true;
	int playState;
	boolean isMoveStop = false;
	boolean isShowPtz = false;
	public Handler stopHandler = new Handler();
	StopRunable stopRunble = new StopRunable();
	public Handler clickHandler = new Handler();
	int playWidth = 0, playHight = 0;
	int row = 0;
	public int total = 0;
	public int viewsNum;
	ShowStopLayoutListener showListener;
	public boolean fragmentIsStop = false;
	StateChangeListener stateChangeListener;
	private boolean isShowContorlBtn = false;
	long reconnectTime;
	int[] iPlayFlowState = new int[PlayNumber];
	Handler handler = new Handler() {
		// boolean IsTempPPT = false;
		// boolean IsTempAudio = false;

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.what) {
			case STATE:
				sendSateMessage(msg);
				break;

			default:
				break;
			}

		}
	};

	public void sendSateMessage(Message msg) {
		stateChangeListener.stateChange(msg.arg1, msg.arg2,
				msg.arg2 == PLAYING ? canvas[msg.arg1].getPlayFrameRate() : "");
		stateChangeListener.isPlaying(msg.arg1, msg.arg2 == PLAYING ? true
				: false);
		stateChangeListener.isRecord(msg.arg1,
				canvas[msg.arg1].getVideoRecordState());
	}

	public void sendSateMessage(int msg) {
		stateChangeListener.stateChange(index, msg,
				msg == PLAYING ? canvas[index].getPlayFrameRate() : "");
		stateChangeListener.isPlaying(index, msg == PLAYING ? true : false);
		stateChangeListener
				.isRecord(index, canvas[index].getVideoRecordState());
	}

	private boolean isShow;

	public PlayLayout(Context context) {

		super(context);

		// TODO Auto-generated constructor stub
	}

	public PlayLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

		// TODO Auto-generated constructor stub
	}

	public PlayLayout(Context context, AttributeSet attrs) {

		super(context, attrs);

		// TODO Auto-generated constructor stub

	}

	/**
	 * 
	 * @param con
	 * @param isScreenScale
	 *            是否是适应屏幕尺寸
	 */
	public void initeView(Context con, boolean isScreenScale) {
		this.con = con;
		for (int i = 0; i < canvas.length; i++) {
			canvas[i] = new VideoCanvas(0, 0, con, isScreenScale);
			ci[i] = new CanvasInfo();// 记录播放屏幕的位置，与宽高

			addView(canvas[i].getView());
		}
		selectCanvas(index);

	}

	public void initeData(PlayNode node, int stream) {

		if (canvas[index] != null) {
			if (canvas[index].isPrepared() && iPlayFlowState[index] == PLAYING) {
				try {
					canvas[index].stop();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			canvas[index].Prepare(node.getName(), node.getDeviceId(), true,
					node.getRoute(), stream);
//			if (canvas[index] != null && canvas[index].isPrepared()&&tvTitle!=null) {
//				tvTitle.setText(canvas[index].Name+"");
//			}
			startThread();
		}

	}

	public void initeListData(List<PlayNode> nodelist, int stream) {

		for (int i = 0; i < nodelist.size(); i++) {
			if (i < canvas.length) {
				PlayNode node = nodelist.get(i);
				if (canvas[i] != null) {
					if (canvas[i].isPrepared() &&canvas[i].isPlayed()) {
						try {
							canvas[i].stop();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

					canvas[i].Prepare(node.getName(), node.getDeviceId(), true,
							node.getRoute(), stream);
					startThread();
				}

			}

		}
//		if (canvas[index] != null && canvas[index].isPrepared()&&tvTitle!=null) {
//			tvTitle.setText(canvas[index].Name+"");
//		}
	}

	public void startThread() {

		if (isRun) {
			return;
		} else {
			isRun = true;
		}

		new Thread() {

			@Override
			public void run() {
				try {

					while (isRun) {

//						if (ApplicationUtils.netOK) {
							for (int i = 0; i < canvas.length; i++) {
								int state = canvas[i].getState();
								if (state == -201 || state == -222) { // 创建camera的时候
																		// //
																		// 状态值为-201//
																		// ,将状态置为1
									// 表示连接中
									state = CONNECTTING;
								}
								reconnet(i, state);
								if (i == index) {
									// LogOut.d("iPlayFlowState", "第" + i +
									// "画面,状态是："
									// + iPlayFlowState[i]);
									
									iPlayFlowState[i]=state;
									handler.sendMessage(Message.obtain(handler,
											STATE, i, iPlayFlowState[i]));
								}
								Thread.sleep(50);
							}
//						} else {
//							Thread.sleep(5000);
//						}

					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}.start();
	}
	
	public void stopThread(){
		
	}

	public void reconnet(int index, int state) {
		if (iPlayFlowState[index] == STOP) {
			return;
		}
		if (state == NPC_D_MPI_MON_ERROR_USERID_ERROR
				|| state == NPC_D_MPI_MON_ERROR_REJECT_ACCESS
				|| state == NPC_D_MPI_MON_ERROR_USERPWD_ERROR) { // 如果用户名密码错误，无权限，不需要重连
			iPlayFlowState[index] = state;
			return;
		}
		switch (iPlayFlowState[index]) {
		case READY:

			break;
		case CONNECTTING:// 等待连接
		{
			if (state <= 0) {
				// LogOut.i("playState", "等待连接中，state=" + state);
				long current = System.currentTimeMillis();
				// iPlayFlowState[index] = CONNECTTING_FAIL;
				// if (current - reconnectTime > 20000) {
				// reconnectTime = current;
				//
				// handler.post(new PlayRunnble(index));
				//
				// // LogOut.e("playState", "等待连接中，超时重连设备22222.");
				// }
			}
			// else if (state == 1) {
			// long current = System.currentTimeMillis();
			// if (current - reconnectTime > 30000) {
			// reconnectTime = current;
			// handler.post(new PlayRunnble(index));
			// .
			// LogOut.LogError("playState", "等待连接中，超时重连设备.");
			// }
			// }
			else if (state == 2) {
				iPlayFlowState[index] = PLAYING;
				reconnectTime = System.currentTimeMillis();
			} else if (state == 3) {
				iPlayFlowState[index] = CONNECTTING_FAIL;
				reconnectTime = System.currentTimeMillis();

				// LogOut.e("playState", "连接设备失败.");
			}
			break;
		}
		case PLAYING:// 正在播放
		{
			if (state < 0) {
				long current = System.currentTimeMillis();
				if (current - reconnectTime > 10000) {
					iPlayFlowState[index] = CONNECTTING_FAIL;
					reconnectTime = current;
				}
			} else if (state != 2) {
				iPlayFlowState[index] = CONNECTTING_FAIL;
				reconnectTime = System.currentTimeMillis();
			}
			break;
		}
		case CONNECTTING_FAIL:// 连接失败
		{
			long current = System.currentTimeMillis();
			if (current - reconnectTime > 6000) {
				// Reconnect(i);
				handler.post(new PlayRunnble(index));
				// LogOut.e("playState", "连接失败，重连设备.");
				// iPlayFlowState = CONNECTTING;
				// reconnectTime=current;
			}
			break;
		}

		}

	}

	class ReconnectRun implements Runnable {

		int index;

		public ReconnectRun(int index) {
			this.index = index;
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			reconnet(index, index);
		}

	}

	public boolean isLand() {
		return isLand;
	}

	public void setLand(boolean isLand) {
		this.isLand = isLand;
		ViewTreeObserver vto = getViewTreeObserver();
		vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
			@Override
			public boolean onPreDraw() {

				int hight = getMeasuredHeight();
				int width = getMeasuredWidth();
				if (width != playWidth && playHight != hight) {
					playHight = hight;
					playWidth = width;
//					if (isSinglePlayView) { // 全屏展示一个摄像头
						canvasToOne(index);
//					} else
//						canvas();
					// selectCanvas(index);
				}
				return true;
			}
		});
	}

	public int gettotal() {
		return total;
	}

	public void settotal(int total) {
		this.total = total;
	}

	public boolean isRun() {
		return isRun;
	}

	public void stopRun() {
		this.isRun = false;
		stop();
	}

	public void release() {

		if (canvas[index].isPrepared()) {
			canvas[index].release();
		}

	}

	public void setPTZ(int command, int length) {
		if (canvas[index].isPlayed()) {
			canvas[index].player.SetPtz(command, length);
		}

	}

	class PlayRunnble implements Runnable {
		int index;

		public PlayRunnble(int index) {
			this.index = index;
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			Reconnect(index);
		}

	}

	public synchronized void Reconnect(int index) {

		if (canvas[index].isPrepared()) {
			if (canvas[index].isPlayed()) {
				canvas[index].stop();
				return;
			}
			iPlayFlowState[index] = CONNECTTING;
			reconnectTime = System.currentTimeMillis();
			canvas[index].Reconnect();
		}

	}

	public void play() {

		if (canvas[index].isPrepared()) {
			if (canvas[index].isPlayed()) {
				canvas[index].stop();
				return;
			}
			iPlayFlowState[index] = CONNECTTING;
			reconnectTime = System.currentTimeMillis();
			canvas[index].Play();
		}

	}

	public void playAll() {
		for (int i = 0; i < canvas.length; i++) {
			if (canvas[i].isPrepared()) {
				if (canvas[i].isPlayed()) {
					canvas[i].stop();
					return;
				}
				iPlayFlowState[i] = CONNECTTING;
				reconnectTime = System.currentTimeMillis();
				canvas[i].Play();
			}

		}

	}

	public void snap(String path) throws Exception {

		if (canvas[index].isPrepared()) {
			if (canvas[index].isPlayed()) {
				canvas[index].setSnap(path);
			}
		}
	}

	public void snap() throws Exception {

		if (canvas[index].isPrepared()) {
			if (canvas[index].isPlayed()) {
				canvas[index].setSnap();
			} else {
				Toast.makeText(con, "Snap just can work while playing", Toast.LENGTH_SHORT)
						.show();
			}
		}
	}

	public boolean record() throws Exception {

		if (canvas[index].isPrepared()) {
			if (canvas[index].isPlayed()) {
				canvas[index].setVideo();
				return true;
			} else {

				Toast.makeText(con, "Snap just can work while playing", Toast.LENGTH_SHORT)
						.show();
				return false;
			}
		}
		return false;
	}

	/*public void setAlarm(PlayerClient pc, boolean ifAlarm, Handler handler) {

		if (canvas[index].isPrepared()) {
			if (ifAlarm) {
				new SetAlarmPushThread(con, pc, canvas[index].DevId,
						Utils.getImsi(con), handler).start();
			} else {
				new CancelAlarmPushThread(con, pc, canvas[index].DevId,
						Utils.getImsi(con), handler).start();
			}
		}

	}*/

	public void stop() {
		iPlayFlowState[index] = STOP;
		new Thread() {

			@Override
			public void run() {

				if (canvas[index].isPrepared()) {
					try {

						// LogOut.e("Stop()", "Stop()---->");
						canvas[index].Stop();

					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			}

		}.start();
		sendSateMessage(iPlayFlowState[index]);
	}

	public void stopChannel() {

		if (canvas[index].isPrepared()) {
			// canvas.Play(index);
			try {
				iPlayFlowState[index] = STOP;
				canvas[index].Stop();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 
	 * 
	 * @param style
	 *            ROW_TOTAL_1 = 1; ROW_TOTAL_4 = 4;ROW_TOTAL_8 = 8; ROW_TOTAL_9
	 *            = 9; ROW_TOTAL_12 = 12; ROW_TOTAL_16 = 16;
	 */
	public void initeCanvas(int style) {
		viewsNum = style;
		switch (style) {
		case ROW_TOTAL_1:
			this.row = 1;
			total = 1;
			isSinglePlayView = true;
			break;
		case ROW_TOTAL_4:
			this.row = 2;
			total = 4;
			break;
		case ROW_TOTAL_8:
			this.row = 2;
			total = 8;
			break;
		case ROW_TOTAL_9:
			this.row = 3;
			total = 9;
			break;
		case ROW_TOTAL_12:
			this.row = 3;
			total = 12;
			break;
		case ROW_TOTAL_16:
			this.row = 4;
			total = 16;
			break;
		case ROW_TOTAL_25:
			// this.row = 5;
			// this.total = 25;
			break;

		}

		setLand(isLand);
		// stopDelayed(false);
		Log.w("isShow", "播放" + total + "个画面");
	}

	// 延时20秒关闭没有显示的画面 fragmentIsStop - fragment是否停止
	public void stopDelayed(boolean fragmentIsStop) {
		this.fragmentIsStop = fragmentIsStop;
		stopHandler.removeCallbacks(stopRunble);
		stopHandler.postDelayed(stopRunble, 10000);
	}

	public void stopAll() {
		stopHandler.removeCallbacks(stopRunble);
		stopHandler.postDelayed(stopRunble, 10);
	}
	public void playCanvas(int style) {

		initeCanvas(style);
		canvas();
	}

	public void canvas() {
		// this.isLand = isLand;
		if (canvas[0] == null) {
			Toast.makeText(con, "无数据", Toast.LENGTH_SHORT).show();
			return;
		}
		// int width = getWidth();
		// int height = getHeight();
		int width = playWidth;
		int height = playHight;
		int w = 0;
		int h = 0;
		int row2 = 0;
		if (isLand) {
			h = height / row;
			row2 = (total / row);
			w = width / row2;
			// LogOut.d("hmaaaa", "land , w:" + width + ",h" + height
			// + ",rows:" + row2);
		} else {
			row2 = row;
			w = width / row2;
			// h = w * 4 / 5;
			// if ((total / row2) * h > height) {
			h = height / (total / row2);
			// }
			// LogOut.d("hmaaaa", "potrat , w:" + width + ",h" + height
			// + ",rows:" + row2);
		}
		int j = 0;
		int k = 0;
		int m = playHight / 2 - ((total / row2) * h) / 2;

		for (int i = 0; i < canvas.length; i++) {

			if (i < total) {
				canvas[i].setPosition(j * w, k * h + m);
				canvas[i].setSize(w, h);

				ci[i].left = j * w;
				ci[i].right = j * w + w;
				ci[i].top = k * h + m;
				ci[i].bottom = k * h + h + m;
				j++;
				if ((i + 1) % row2 == 0) {
					k++;
					j = 0;
				}
				canvas[i].isShow = true;
			} else {
				canvas[i].isShow = false;
				canvas[i].setPosition(0, 0);
				canvas[i].setSize(0, 0);
			}

		}
	}

	/**
	 * 
	 * 
	 */
	public void canvasToOne(int index) {
		// showControlBtn();
		isSinglePlayView = true;
		// int w = width;
		// int w = getWidth();
		int w = playWidth;

		int h;
		if (this.isLand) {
			h = getHeight();
			// h = w * 3 / 4;
			// h = playHight;
		} else {
			// h = w * 4 / 5;
			h = getHeight();
		}
		int m = playHight / 2 - h / 2;
		for (int i = 0; i < canvas.length; i++) {
			if (i == index) {
				canvas[i].setPosition(0, m);
				canvas[i].setSize(w, h);
				canvas[i].isShow = true;
				ci[i].left = 0;
				ci[i].right = w;
				ci[i].top = 0;
				ci[i].bottom = h;

			} else {
				canvas[i].isShow = false;
				canvas[i].setPosition(0, 0);
				canvas[i].setSize(0, 0);
				ci[i].left = 0;
				ci[i].right = 0;
				ci[i].top = 0;
				ci[i].bottom = 0;
				// canvas.setVisibility(View.INVISIBLE);
			}

		}
	}

	class StopRunable implements Runnable {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			for (int i = 0; i < canvas.length; i++) {

				if (canvas[i].isPrepared()) {
					// LogOut.e("isShow", "第" + 0 + "画面停止");
					if (fragmentIsStop) {

						try {
							iPlayFlowState[i] = STOP;
							canvas[i].Stop();
							canvas[i].release();
							stateChangeListener.stateChange(1, 4, "");
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						isRun = false;
					}
				}
			}

		}

	}

	public int getCanvasIndex(float x, float y) {
		for (int i = 0; i < canvas.length; i++) {
			// if (canvas[i].isEnable()) {
			if (x >= ci[i].left && x <= ci[i].right && y >= ci[i].top
					&& y <= ci[i].bottom) {
				return i;
				// }
			}
		}
		return -1;
	}

	int mode = -1;
	private float oldDist;
	private float newDist;

	@Override
	public boolean onTouchEvent(MotionEvent event) {
        /*
		switch (event.getAction() & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:

			int i = getCanvasIndex(event.getX(), event.getY());
			if (i % 2 == 0) {
				if (event.getX() < 30) {
					break;
				}
			}
			if (i == -1) {
				return true;
			}
			// LogOut.i("selectCanvas", "之前选中： " + index + ",当前选中：" + i);
			if (index != i) {
				selectCanvas(i);
			}
			isDoubleClick(index); // 控制全屏
			if (!isSinglePlayView) {
				isShow = false;
			} else {
				isShow = true;
			}
			stateChangeListener.showControlBtn(index, isShow); // 切换控制按钮
			break;
		case MotionEvent.ACTION_UP:

			break;
		case MotionEvent.ACTION_POINTER_DOWN:
			// canvas[index].imgVideo.onPointerDown(event);

			if (event.getPointerCount() > 1) {
				int i1 = getCanvasIndex(event.getX(1), event.getY(1));
				if (i1 == index) {// 两个手指都在同一个画面
					if (canvas[index].getState() == 2)
						canvas[index].imgVideo.setScaleType(ScaleType.MATRIX);
				} else {
					oldDist = spacing(event);
					mode = 1;
				}

			}
			break;
		case MotionEvent.ACTION_MOVE:

			if (mode == 1) {
				if (event.getPointerCount() > 1) {
					newDist = spacing(event);
					if (newDist > oldDist && newDist - oldDist > 100f) {
						if (total == 4) {
							canvasToOne(index);
						} else if (total == 16) {
							playCanvas(9);
						} else if (total == 9) {
							playCanvas(4);
						}
						mode = -1;
					} else if (newDist < oldDist && oldDist - newDist > 100f) {
						if (total == 4) {
							playCanvas(9);
						} else if (total == 9) {
							playCanvas(16);
						}
						mode = -1;
					}
				}
			} else {
				mode = -1;
			}
			break;
		default:
			break;
		}
		*/
		// if (!isShow)
//		if (canvas[index].imgVideo.getScaleType() == ScaleType.MATRIX) {
//			if (canvas[index].deal.set(canvas[index].imgVideo, event)) {
//				canvas[index].imgVideo.setScaleType(ScaleType.FIT_XY);
//			}
//		}
		return true;
	}

	private float spacing(MotionEvent event) {
		float x = event.getX(0) - event.getX(1);
		float y = event.getY(0) - event.getY(1);
		return FloatMath.sqrt(x * x + y * y);
	}

	/**
	 * 拖动状态显示，停止 监听
	 * 
	 * @author Administrator
	 * 
	 */
	public interface ShowStopLayoutListener {
		abstract public void showStateListener(boolean state);

		abstract public void isMoveVisibleListener(boolean isVisible);

		abstract public void isStop(boolean isStop);

	}

	public ShowStopLayoutListener getShowListener() {
		return showListener;
	}

	public void setShowListener(ShowStopLayoutListener showListener) {
		this.showListener = showListener;
	}

	public StateChangeListener getStateChangeListener() {
		return stateChangeListener;
	}

	public void setStateChangeListener(StateChangeListener stateChangeListener) {
		this.stateChangeListener = stateChangeListener;
	}

	/**
	 * 
	 * 
	 * @param index
	 */
	public void selectCanvas(int index) {
		this.index = index;
//		if (canvas[index] != null && canvas[index].isPrepared()&&tvTitle!=null) {
//			tvTitle.setText(canvas[index].Name+"");
//		}
		ResetCanvasBackground();
		canvas[index].setHightLight(true);
		canvas[index].getView().bringToFront();

	}

	public void ResetCanvasBackground() {

		for (int i = 0; i < canvas.length; i++) {
			canvas[i].setHightLight(false);
		}

	}

	/**
	 * 
	 */
	public boolean isDoubleClick(int n) {

		if (count == 0 && index == n) {
			++count;
			fTime = System.currentTimeMillis();
			clickHandler.postDelayed(this, 200);
		} else if (count == 1 && index == n) {
			if (System.currentTimeMillis() - fTime < 500) {
				// LogOut.i("count", "click~~~~~~!!!count is " + count);
				canvas[n].imgVideo.setScaleType(ScaleType.FIT_XY);
				if (!isSinglePlayView) {
					canvasToOne(n);
				} else {
					isSinglePlayView = false;
					canvas();
				}
				return false;
			} else {
				count = 0;
			}
		}

		return true;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		count = 0;
	}

	/*public static String GetDescription(Context con, int state) {
		String des = con.getString(R.string.stop);

		switch (state) {
		case SDKError.Statue_Ready:
			des = con.getString(R.string.ready);
			break;
		case SDKError.Statue_PLAYING:
			// des = con.getString(R.string.playing);
			des = "";
			break;
		case SDKError.Statue_STOP:
			des = con.getString(R.string.stop);
			break;
		case SDKError.Statue_ConnectFail:
			des = con.getString(R.string.connect_fail);
			break;
		case SDKError.NET_ERROR:
			des = con.getString(R.string.net_error);
			break;
		case SDKError.NET_NODATA_ERROR:
			des = con.getString(R.string.no_data);

		case SDKError.Exception_ERROR:
			des = con.getString(R.string.exception_error);
			break;
		case SDKError.NosupportDevice_ERROR:
			des = con.getString(R.string.unsupport_device);
			break;
		case SDKError.Beyondmaxchannels_ERROR:
			des = con.getString(R.string.max_channel);
			break;
		}
		return des;
	}*/

	public void setScreenScale(boolean isScreenScale) {

		for (int i = 0; i < canvas.length; i++) {
			canvas[i].setScreenScale(isScreenScale);
		}

		// LogOut.LogInfo("isScreenScale", "isScreenScale : " + isScreenScale);
	}

	public boolean setIsAudio(boolean open) {
		// IsAudio = isAudio;
		// for (int i = 0; i < canvas.length; i++) {
		//
		// }

		return canvas[index].setIsAudio(open);

	}

	public boolean IsAudio() {
		// IsAudio = isAudio;
		// for (int i = 0; i < canvas.length; i++) {
		//
		// }

		return canvas[index].IsAudio();

	}

	public boolean getAudio() {
		if (canvas[index].isPrepared()) {
			return !canvas[index].player.GetIsVoicePause();
		} else
			return false;

	}

	public void setPPT(boolean isOpen) {
		canvas[index].setPPT(isOpen);
	}

	public boolean isPPT() {

		return canvas[index].IsPPt();
	}

	public boolean isPrepared() {
		return canvas[index].isPrepared();
	}

	public int[] getPlayRate() {
		if (canvas[index].isPrepared() && canvas[index].isPlayed()) {
			return canvas[index].getPlayRate();
		} else {
			return null;
		}

	}

	/**
	 * 流量数据统计
	 * 
	 * @return
	 */
	public long getDataCount() {
		return canvas[index].getDatacount();
	}

	public class CanvasInfo {
		public int left;
		public int right;
		public int top;
		public int bottom;
	}

	TextView tvTitle;

	public void setTitleView(TextView textView) {
		this.tvTitle = textView;
	}
}
